package com.wenwei.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jakewharton.rxbinding.widget.RxTextView;
import com.wenwei.parking.BaseActivity;
import com.wenwei.parking.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func2;

/**
 * Created by Administrator on 2017/8/21.
 */
public class BindPayActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.name_et)
    EditText nameEt;
    @Bind(R.id.code_et)
    EditText codeEt;
    @Bind(R.id.bind_btn)
    TextView bindBtn;

    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_bind_pay;
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("支付宝绑定");

        Observable<CharSequence> phoneObservable = RxTextView.textChanges(nameEt);
        Observable<CharSequence> psObservable = RxTextView.textChanges(codeEt);
        Observable.combineLatest(phoneObservable, psObservable, new Func2<CharSequence, CharSequence, Boolean>() {
            @Override
            public Boolean call(CharSequence charSequence, CharSequence charSequence2) {
                return !charSequence.toString().equals("") && !charSequence2.toString().equals("");
            }
        }).subscribe(new Action1<Boolean>() {
            @Override
            public void call(Boolean aBoolean) {
                bindBtn.setEnabled(aBoolean);
                if(aBoolean){
                    bindBtn.setBackgroundResource(R.drawable.button_state_2);
                }else{
                    bindBtn.setBackgroundResource(R.drawable.button_state_1);
                }
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.base_back, R.id.bind_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finish();
                break;
            case R.id.bind_btn:
                showToast("绑定成功");
                finish();
                break;
        }
    }
}
